<template>
<div>
    <h2 class="text-center ma-2">首次安装配置</h2>
    <v-card class="ma-2">
        <studioModel @server_config="saveCurrentConfig" @proxy_config="saveProxyConfig"></studioModel>
    </v-card>
</div>
</template>

<script setup lang="ts">
import { useRouter } from 'vue-router';
import studioModel from "@renderer/components/serverConfig/studioModel.vue"
import type { IStudio, IHttpProxy } from "@shared/constans/types/configType"
import { useAppStore } from "../stores/appConfig";

const router = useRouter();
const app_store = useAppStore();


function saveCurrentConfig(server_config: IStudio) {
    let data = {
        username: server_config.username,
        password: server_config.password,
        server_name: server_config.server_name,
        server_url: server_config.server_url
    }
    app_store.setSystemConfig(server_config)
    window.api.saveSystemConfig(data);
    router.push({name: 'home'})
}

function saveProxyConfig(proxy_config: IHttpProxy) {
    let data = {
        enable: proxy_config.enable,
        host: proxy_config.host,
        port: proxy_config.port
    }
    app_store.setHttpProxy(proxy_config)
    window.api.setConfig("http_proxy", data, "perf");
}
</script>
